home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / capmou_1 / frmcapmo.frm (.txt)
Encoding:
Visual Basic Form  |  1998-09-17  |  5.6 KB  |  153 lines

  1. VERSION 5.00
  2. Begin VB.Form frmCapMouse 
  3.    AutoRedraw      =   -1  'True
  4.    Caption         =   "SetCapture Demo"
  5.    ClientHeight    =   2550
  6.    ClientLeft      =   1395
  7.    ClientTop       =   1530
  8.    ClientWidth     =   4965
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   170
  11.    ScaleMode       =   3  'Pixel
  12.    ScaleWidth      =   331
  13.    Begin VB.PictureBox Picture1 
  14.       Height          =   1095
  15.       Index           =   3
  16.       Left            =   3780
  17.       ScaleHeight     =   69
  18.       ScaleMode       =   3  'Pixel
  19.       ScaleWidth      =   69
  20.       TabIndex        =   4
  21.       Top             =   180
  22.       Width           =   1095
  23.       Begin VB.Label Label2 
  24.          Alignment       =   2  'Center
  25.          BackStyle       =   0  'Transparent
  26.          Caption         =   "Caption Four"
  27.          Height          =   480
  28.          Index           =   3
  29.          Left            =   210
  30.          TabIndex        =   8
  31.          Top             =   300
  32.          Width           =   600
  33.       End
  34.    End
  35.    Begin VB.PictureBox Picture1 
  36.       Height          =   1095
  37.       Index           =   2
  38.       Left            =   2565
  39.       ScaleHeight     =   69
  40.       ScaleMode       =   3  'Pixel
  41.       ScaleWidth      =   69
  42.       TabIndex        =   3
  43.       Top             =   180
  44.       Width           =   1095
  45.       Begin VB.Label Label2 
  46.          Alignment       =   2  'Center
  47.          BackStyle       =   0  'Transparent
  48.          Caption         =   "Caption Three"
  49.          Height          =   480
  50.          Index           =   2
  51.          Left            =   210
  52.          TabIndex        =   7
  53.          Top             =   300
  54.          Width           =   600
  55.       End
  56.    End
  57.    Begin VB.PictureBox Picture1 
  58.       Height          =   1095
  59.       Index           =   1
  60.       Left            =   1320
  61.       ScaleHeight     =   69
  62.       ScaleMode       =   3  'Pixel
  63.       ScaleWidth      =   69
  64.       TabIndex        =   2
  65.       Top             =   180
  66.       Width           =   1095
  67.       Begin VB.Label Label2 
  68.          Alignment       =   2  'Center
  69.          BackStyle       =   0  'Transparent
  70.          Caption         =   "Caption Two"
  71.          Height          =   480
  72.          Index           =   1
  73.          Left            =   210
  74.          TabIndex        =   6
  75.          Top             =   300
  76.          Width           =   600
  77.       End
  78.    End
  79.    Begin VB.PictureBox Picture1 
  80.       Height          =   1095
  81.       Index           =   0
  82.       Left            =   75
  83.       ScaleHeight     =   69
  84.       ScaleMode       =   3  'Pixel
  85.       ScaleWidth      =   69
  86.       TabIndex        =   0
  87.       Top             =   180
  88.       Width           =   1095
  89.       Begin VB.Label Label2 
  90.          Alignment       =   2  'Center
  91.          BackStyle       =   0  'Transparent
  92.          Caption         =   "Caption One"
  93.          Height          =   480
  94.          Index           =   0
  95.          Left            =   210
  96.          TabIndex        =   5
  97.          Top             =   300
  98.          Width           =   600
  99.       End
  100.    End
  101.    Begin VB.Label Label1 
  102.       Caption         =   $"frmCapMouse.frx":0000
  103.       Height          =   675
  104.       Left            =   300
  105.       TabIndex        =   1
  106.       Top             =   1605
  107.       Width           =   4170
  108.    End
  109. Attribute VB_Name = "frmCapMouse"
  110. Attribute VB_GlobalNameSpace = False
  111. Attribute VB_Creatable = False
  112. Attribute VB_PredeclaredId = True
  113. Attribute VB_Exposed = False
  114.   ' demo project showing how to use the SetCapture API function
  115.   ' by Bryan Stafford of New Vision Software
  116.   ' this demo is released into the public domain "as is" without
  117.   ' warranty or guaranty of any kind.  In other words, use at
  118.   ' your own risk.
  119.   Option Explicit
  120.   ' SetCapture directs ALL mouse input to the window that has the mouse
  121.   ' "captured".  as you will see in the demo this can be very useful for
  122.   ' detecting when the mouse leaves a particular area on one of your forms.
  123.   Private Declare Function ReleaseCapture& Lib "user32" ()
  124.   Private Declare Function GetCapture& Lib "user32" ()
  125.   Private Declare Function SetCapture& Lib "user32" (ByVal hWnd&)
  126. Private Sub Label2_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  127.   ' pass on the event to the picture box
  128.   Picture1_MouseMove Index, Button, Shift, X, Y
  129. End Sub
  130. Private Sub Label2_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  131.   ' make sure that we keep the capture since the capture is released whenever the mouse is clicked
  132.   Call SetCapture(Picture1(Index).hWnd)
  133. End Sub
  134. Private Sub Picture1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  135.   ' if the mouse is already captured check to see if
  136.   ' it's still within the boundaries of the control
  137.   If GetCapture() = Picture1(Index).hWnd Then
  138.     If ((X < 0) Or (X > Picture1(Index).Width)) Or ((Y < 0) Or (Y > Picture1(Index).Height)) Then
  139.       ' if the mouse is outside the bounds of the control
  140.       ' release the mouse and reset the backcolor
  141.       Call ReleaseCapture
  142.       Picture1(Index).BackColor = &H8000000F
  143.     End If
  144.   Else ' otherwise capture the mouse and change the backcolor of the control
  145.     Picture1(Index).BackColor = &HFFFF&
  146.     Call SetCapture(Picture1(Index).hWnd)
  147.   End If
  148. End Sub
  149. Private Sub Picture1_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  150.   ' make sure that we keep the capture since the capture is released whenever the mouse is clicked
  151.   Call SetCapture(Picture1(Index).hWnd)
  152. End Sub
  153.